<?php

namespace App\Http\Traits;

use Cache;

trait CacheTrait
{
    private $cache_minutes             = 10080; // 60*24*7
    private $prefix_projects           = 'projects_';
    private $prefix_deploy_process_log = 'deploy_process_log_';

    public function getProjects($user_id)
    {
        return Cache::get($this->prefix_projects . $user_id);
    }

    public function setProjects($user_id, $projects)
    {
        return Cache::add($this->prefix_projects . $user_id, $projects, $this->cache_minutes);
    }

    public function forgetProjects($user_id)
    {
        return Cache::forget($this->prefix_projects . $user_id);
    }

    public function setDeployProcessLog($user_name, $server_type, $project_namespace, $log)
    {
        Cache::add($this->prefix_deploy_process_log . $user_name . '_' . $server_type . '_' . base64_encode($project_namespace), $log, $this->cache_minutes);
    }

    public function forgetDeployProcessLog($user_name, $server_type, $project_namespace)
    {
        Cache::forget($this->prefix_deploy_process_log . $user_name . '_' . $server_type . '_' . base64_encode($project_namespace));
    }

    public function getDeployProcessLog($user_name, $server_type, $project_namespace)
    {
        return Cache::get($this->prefix_deploy_process_log . $user_name . '_' . $server_type . '_' . $project_namespace);
    }
}
